#define _CRT_SECURE_NO_WARNINGS 1
#include"Queue.h"
#include"stack.h"

typedef int BTDataType;

typedef struct BTnode
{
	BTDataType a;
	struct BTnode* left;
	struct BTnode* right;
}BTNode;

BTNode* buynewnode( BTDataType x)
{
	BTNode* newnode = (BTNode*)malloc(sizeof(BTNode));
	if (newnode == NULL)
	{
		perror("malloc  fail");
		return;
	}
	newnode->a = x;
	newnode->left = NULL;
	newnode->right = NULL;

	return newnode;
}


BTNode* CreateTree()
{
	BTNode* node1 = buynewnode(1);
	BTNode* node2 = buynewnode(2);
	BTNode* node3 = buynewnode(3);
	BTNode* node4 = buynewnode(4);
	BTNode* node5 = buynewnode(5);
	BTNode* node6 = buynewnode(6);
	node1->left = node2;
	node1->right = node4;
	node2->left = node3;
	node4->left = node5;
	node4->right = node6;

	return node1;
}
void peordertree(BTNode* root)
{
	if (root == NULL)
	{
		printf("NULL ");
		return ;
	}
	printf("%d ", root->a);
	peordertree(root->left);
	peordertree(root->right);

}
void afterordertree(BTNode* root)
{
	if (root == NULL)
	{
		printf("NULL ");
		return;
	}
	afterordertree(root->left);
	printf("%d ", root->a);
	afterordertree(root->right);
}
void midordertree(BTNode* root)
{
	if (root == NULL)
	{
		printf("NULL ");
		return;
	}
	midordertree(root->left);
	midordertree(root->right);
	printf("%d ", root->a);
	
}
int main()
{
	/*Queuetest();*/
	/*STtest();*/
	BTNode* root = CreateTree();
	peordertree(root);
	printf("\n");
	afterordertree(root);
	printf("\n");
	midordertree(root);
	return 0;
}